<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全选、不选、反选</title>
    <script>
        window.onload=function(){
            var oBtn1=document.getElementById('btn1');
            var oBtn2=document.getElementById('btn2');
            var oBtn3=document.getElementById('btn3');
            var oDiv=document.getElementById('div1');
            var aCh=oDiv.getElementsByTagName('input');
            oBtn1.onclick=function(){
                //aCh[0].checked=true;
                for(var i=0; i<aCh.length;i++){
                    aCh[i].checked=true;
                }

            };
            oBtn2.onclick=function(){
                //aCh[0].checked=true;
                for(var i=0; i<aCh.length;i++){
                    aCh[i].checked=false;
                }

            };
            oBtn3.onclick=function(){
                //aCh[0].checked=true;
                for(var i=0; i<aCh.length;i++){
                    if(aCh[i].checked==true){
                        aCh[i].checked=false;
                    }
                    else{
                        aCh[i].checked=true;
                    }

                }

            };
        };
    </script>

</head>
<body>
<input type="button" id="btn1" value="全选"><br>
<input type="button" id="btn2" value="不选"><br>
<input type="button" id="btn3" value="反选"><br>
<div id="div1">
    <input type="checkbox"><br>
    <input type="checkbox"><br>
    <input type="checkbox"><br>
    <input type="checkbox"><br>
    <input type="checkbox"><br>
    <input type="checkbox"><br>
    <input type="checkbox"><br>
    <input type="checkbox">
</div>

</body>
</html>
<!--ture/false是布尔值-->